(function(angular){
	'use strict';
	angular.module('fs.waf').controller('cda.patchTemplate.viewController',viewController);
	viewController.$inject = ['$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'patchTemplateService', 'modalService'];
	function viewController ($scope, Constants, layoutConfig, validatorConfig, gridService, authService, patchTemplateService, modalService){
		var ctrl = this, patchTemplateInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
//		ctrl.validatorConfig = validatorConfig;
		ctrl.patchTemplate = {};
		ctrl.patchTemplate.dPatchTplParms = ctrl.patchTemplate.dPatchTplParms || [];
		
		ctrl.init = function (){
			var params = {
					dpatchTplId : patchTemplateInfo.dpatchTplId
			};
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.dPatchTplParms.tableConfigs.table);
			ctrl.innerGridOptions.data = 'vm.patchTemplate.dPatchTplParms';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			ctrl.parmTypeOptions = parmTypeOptions().data;
			
			return authService.view(params).then(function(response){
				patchTemplateService.initOptions(ctrl).then(function(result){
					ctrl.patchTemplate = response.data || patchTemplateInfo;
					ctrl.patchTemplate = response.data || params;
					ctrl.patchTemplate.dPatchTplParms = ctrl.patchTemplate.dPatchTplParms || [];
					
				});
			},angular.noop());
		};		

		function parmTypeOptions() {
			return {
				"data" : [ {
					"label" : "Date",
					"value" : "java.sql.Date"
				},{
					"value" : "java.lang.Double",
					"label" : "Double"
				}, {
					"value" : "java.lang.Float",
					"label" : "Float"
				} , {
					"value" : "java.lang.Integer",
					"label" : "Integer"
				} , {
					"value" : "java.lang.Long",
					"label" : "Long"
				} , {
					"value" : "java.lang.Short",
					"label" : "Short"
				} , {
					"value" : "java.lang.String",
					"label" : "String"
				} , {
					"value" : "java.sql.Timestamp",
					"label" : "Timestamp"
				}]
			};
		}
		
		ctrl.showDPatch = function() {
			modalService.openCustomDialogs({
				'dialogsModule' : 'cda.dataPatch',
				'params' : ctrl.patchTemplate
				});
		};
	}	
})(angular);